package cn.zwx.search.service.impl;

import cn.zwx.search.SearchExampleApplication;
import cn.zwx.search.model.req.OrderInfoReq;
import cn.zwx.search.model.resp.OrderInfoResp;
import cn.zwx.search.service.QueryOrderService;
import cn.zwx.search.utils.ElasticSearchBuilderUtil;
import cn.zwx.search.utils.ElasticsearchUtil;
import com.github.pagehelper.PageInfo;
import lombok.SneakyThrows;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description: 查询订单API
 * @projectName:search-example
 * @see:cn.zwx.search.service.impl
 * @author:zhangwenxue
 * @createTime:2020/10/23 15:52
 * @version:1.0
 */
@Service
public class QueryOrderServiceImp  implements QueryOrderService {

    private static Logger logger= LoggerFactory.getLogger(SearchExampleApplication.class);

    @Autowired
    private ElasticsearchUtil elasticsearchUtil;




    /**
     * @description 订单主搜索
     * @return java.lang.String
     * @author zhangwenxue
     * @createTime 2020/10/23 15:55
     **/
    @SneakyThrows
    @Override
    public PageInfo<OrderInfoResp> mainSearch(OrderInfoReq req) {
        //1.构建查询对象
        SearchSourceBuilder searchSourceBuilder = ElasticSearchBuilderUtil.getSearchSourceBuilderForOrder(req);
        //2.执行查询并封装结果集
        PageInfo<OrderInfoResp> pageInfo = elasticsearchUtil.search(searchSourceBuilder, req.getPageNum(), req.getPageSize(), OrderInfoResp.class);
        //3.返回参数
        return pageInfo;
    }
}
